package com.captain.special.二叉树.简单;

import com.captain.leetcode.TreeNode;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/5/8 23:09
 */
public class 二叉树中第二小的节点671 {
    int min;
    int sMin;

    public int findSecondMinimumValue(TreeNode root) {
        sMin = -1;
        min = root.val;
        recur(root);
        return sMin;
    }

    public void recur(TreeNode node) {
        if (node == null) return;
        if (min < node.val) {
            if (sMin != -1) {
                sMin = Math.min(node.val,sMin);
            }else {
                sMin = node.val;
            }
        }
        recur(node.left);
        recur(node.right);
    }
}
